<template>
	<div>
		<div class="pic">
			<div class="in">
				<router-link to="/adm/secondtype"><div class="pcc"><返回</div></router-link>
				<div class="pcc1">
					父的id -	[ {{a}} ]
				</div>
					<div class="pcc2">
						父的名字 - [ {{a1}} ]
					</div>
					<hr/>
				<div v-model="user.pid=a">
					
				<!-- </div><div v-model="user.id=this.a"></div> -->
					
				</div>
				<div>
					 <input placeholder="二级类型名称"  v-model="user.name" />
				</div>
				<div>
					<input placeholder="显示顺序" v-model="user.prio" />
				</div>
				<div class="pcc3">
					<router-link to="/adm/secondtype">
						<button class="a" @click="doadd()">添加</button>
					</router-link>
				</div>
				
					
				
			</div>
		</div>
	</div>
</template>

<script>
	export default{
		name:"add2",
		data() {
			return {
				user:{
					pid:'',
					id: '',
					name: '',
					prio: '',
				},
				from: [],
				a:'',
				a1:''
			}
		},
		methods: {
		doadd(){
			if(this.from.id==this.a){
				let fd=new FormData();
				// fd.append('id',this.a);
				fd.append('pid',this.a);
				fd.append('name',this.user.name);
				fd.append('prio',this.user.prio);
				console.log(fd);
				
					this.$axios.post("/api/adm/type/add", fd).then((resp) => {
				if(resp.status==200){
					this.user=resp.data.data;
					console.log(resp.data.data);
				}
			}).catch((error)=>{
				console.log(error);
			})
				}
			
		},
		add(m,m1){
			this.$get("/api/adm/type/findById/" + m).then((resp) => {
				this.from=resp.data.data;
				console.log(this.from);
				})
				this.a=m;
				this.a1=m1;
				console.log(this.a)
			}
		},
		
		
		mounted() {
			let m= this.$route.query.id1
			let m1= this.$route.query.name1
			console.log(m1);
			console.log(m);
			this.add(m,m1)
			console.log(this.$route)
			this.from = this.$route.query;
			console.log(this.from)
		}
	}
</script>

<style>
	.pcc{
		color: #93c8c5;
		font-size: 2rem;
	}
	.pcc1{
		font-size: 1.5rem;
	}
	.pcc2{
		font-size: 1.5rem;
	}
	.pcc3{
		margin-top: 1rem;
	}
</style>
